using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using KingSite.Shop.Core.Mvc;
using KingSite.Shop.Core.Service;
using KingSite.Shop.Service;
using KingSite.Shop.Domain;
using KingSite.Shop.Domain.ShowDataModel;


namespace KingSite.Shop.Web.Controllers
{
    public class ShareAscxController : BaseController
    {
        ICategoryService _categoryService;
        IIndexRecommendService _irService;
        INewsService _newsService;
        ICustomerService _customerService;

        IParserUrlParamater pup = new ParserUrlParamater();
        //
        // GET: /ShareAscx/

        public ShareAscxController(ICategoryService categoryService, IIndexRecommendService irService, INewsService newsService, ICustomerService customerService) {
            _categoryService = categoryService;
            _irService = irService;
            _newsService = newsService;
            _customerService = customerService;
        }
        
        public ActionResult TopMenu()
        {
            IList<Category> list = _categoryService.GetTopLevelCategory();
            ViewData.Model = list;
            return View();
        }

        public ActionResult TopNavigationForGoods(int id) {
            IList<Category> list = _categoryService.GetCategoryPath(id);
            for (int i = 0; i <= list.Count - 1;i++ ) {
                list[i].Path = pup.Compile(list[i].Path);
            }
            ViewData.Model = list;
            return View("TopNavigation");
        }

        public ActionResult TopNavigationForGoodsList(string id) {

            IList<Category> list = _categoryService.GetCategoryPath(id);
            for (int i = 0; i <= list.Count - 1; i++) {
                list[i].Path = pup.Compile(list[i].Path);
            }
            ViewData.Model = list;
            return View("TopNavigation");
        }

        public ActionResult LogOnUserControl() {

            Customer c = _customerService.Find(User.Identity.Name);
            if (c != null) {
                ViewData["UserName"] = c.Name;
            }

            return View();
        }

        public ActionResult IndexRecommend(int cid, int rid)
        {
            IList<IndexRecommendModel> list = _irService.GetIndexRecommendList(cid, rid);
            ViewData.Model = list;
            return View();
        }

        public ActionResult TopNews(int n, int cid)
        {
            IList<News> list = _newsService.GetTopNTopic(n, cid);
            ViewData.Model = list;
            return View();
        }

    }
}
